package com.centaline.androidsalesblog.rx.database;

import com.centaline.androidsalesblog.constants.AppConstant;
import com.centaline.androidsalesblog.model.databaseobject.RailLineDo;

import org.litepal.crud.DataSupport;

import java.util.ArrayList;

import rx.Observable;
import rx.Subscriber;

/**
 * 下拉菜单-地铁线路
 * Created by guilin on 16/1/25.
 */
final class MetroOnSubscribe implements Observable.OnSubscribe<ArrayList<RailLineDo>> {

    @Override
    public void call(Subscriber<? super ArrayList<RailLineDo>> subscriber) {
        final ArrayList<RailLineDo> list = new ArrayList<>();
        list.addAll(DataSupport.where("cityCode = ?", AppConstant.CityCode).find(RailLineDo.class));
        for (RailLineDo railLineDo : list) {
            railLineDo.findRailWayList();
        }
        if (!subscriber.isUnsubscribed()) {
            subscriber.onNext(list);
        }
        subscriber.onCompleted();
    }

}
